package com.betterjr.modules.risk.loan.entity;

import java.math.BigDecimal;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.mapper.CustDateJsonSerializer;
import com.betterjr.common.utils.BTAssert;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@Access(AccessType.FIELD)
@Entity
@Table(name = "t_scf_loan_transaction")
public class LoanTransaction implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = -7249650276059008476L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "VARCHAR")
    @MetaData(value = "流水号", comments = "流水号")
    private String id;

    /**
     * 供应商名称
     */
    @Column(name = "C_CUSTNAME", columnDefinition = "VARCHAR")
    @MetaData(value = "供应商名称", comments = "供应商名称")
    private String custName;

    /**
     * 供应商企业代码
     */
    @Column(name = "C_CUSTCODE", columnDefinition = "VARCHAR")
    @MetaData(value = "供应商企业代码", comments = "供应商企业代码")
    private String custCode;

    /**
     * 核心企业名称
     */
    @Column(name = "C_CORENAME", columnDefinition = "VARCHAR")
    @MetaData(value = "核心企业名称", comments = "核心企业名称")
    private String coreName;

    /**
     * 核心企业编号
     */
    @Column(name = "L_CORENO", columnDefinition = "INTEGER")
    @MetaData(value = "核心企业编号", comments = "核心企业编号")
    private Long coreNo;

    /**
     * 资金提供方名称
     */
    @Column(name = "C_FACTORY_NAME", columnDefinition = "VARCHAR")
    @MetaData(value = "资金提供方名称", comments = "资金提供方名称")
    private String factoryName;

    /**
     * 资金提供方编号
     */
    @Column(name = "L_FACTORYNO", columnDefinition = "INTEGER")
    @MetaData(value = "资金提供方编号", comments = "资金提供方编号")
    private Long factoryNo;

    /**
     * 交易应付金额
     */
    @Column(name = "F_TRADE_MONEY", columnDefinition = "DOUBLE")
    @MetaData(value = "交易应付金额", comments = "交易应付金额")
    private BigDecimal balance;

    /**
     * 交易应付日期
     */
    @Column(name = "C_TRADE_DATE", columnDefinition = "VARCHAR")
    @MetaData(value = "交易应付日期", comments = "交易应付日期")
    @JsonSerialize(using = CustDateJsonSerializer.class)
    private String payDate;

    /**
     * 订单编号
     */
    @Column(name = "C_ORDERNO", columnDefinition = "VARCHAR")
    @MetaData(value = "订单编号", comments = "订单编号")
    private String orderNo;

    /**
     * 贸易合同编号
     */
    @Column(name = "C_CONTRACTNO", columnDefinition = "VARCHAR")
    @MetaData(value = "贸易合同编号", comments = "贸易合同编号")
    private String contractNo;

    /**
     * 发票号码
     */
    @Column(name = "C_RECEIPTNO", columnDefinition = "VARCHAR")
    @MetaData(value = "发票号码", comments = "发票号码")
    private String receiptNo;

    /**
     * 发票金额
     */
    @Column(name = "F_RECEIPTMONEY", columnDefinition = "DOUBLE")
    @MetaData(value = "发票金额", comments = "发票金额")
    private BigDecimal receiptMoney;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCustName() {
        return custName;
    }

    public void setCustName(String custName) {
        this.custName = custName;
    }

    public String getCustCode() {
        return custCode;
    }

    public void setCustCode(String custCode) {
        this.custCode = custCode;
    }

    public String getCoreName() {
        return coreName;
    }

    public void setCoreName(String coreName) {
        this.coreName = coreName;
    }

    public Long getCoreNo() {
        return coreNo;
    }

    public void setCoreNo(Long coreNo) {
        this.coreNo = coreNo;
    }

    public String getFactoryName() {
        return factoryName;
    }

    public void setFactoryName(String factoryName) {
        this.factoryName = factoryName;
    }

    public Long getFactoryNo() {
        return factoryNo;
    }

    public void setFactoryNo(Long factoryNo) {
        this.factoryNo = factoryNo;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }

    public String getPayDate() {
        return payDate;
    }

    public void setPayDate(String payDate) {
        this.payDate = payDate;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getContractNo() {
        return contractNo;
    }

    public void setContractNo(String contractNo) {
        this.contractNo = contractNo;
    }

    public String getReceiptNo() {
        return receiptNo;
    }

    public void setReceiptNo(String receiptNo) {
        this.receiptNo = receiptNo;
    }

    public BigDecimal getReceiptMoney() {
        return receiptMoney;
    }

    public void setReceiptMoney(BigDecimal receiptMoney) {
        this.receiptMoney = receiptMoney;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((balance == null) ? 0 : balance.hashCode());
        result = prime * result + ((contractNo == null) ? 0 : contractNo.hashCode());
        result = prime * result + ((coreName == null) ? 0 : coreName.hashCode());
        result = prime * result + ((coreNo == null) ? 0 : coreNo.hashCode());
        result = prime * result + ((custCode == null) ? 0 : custCode.hashCode());
        result = prime * result + ((custName == null) ? 0 : custName.hashCode());
        result = prime * result + ((factoryName == null) ? 0 : factoryName.hashCode());
        result = prime * result + ((factoryNo == null) ? 0 : factoryNo.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((orderNo == null) ? 0 : orderNo.hashCode());
        result = prime * result + ((payDate == null) ? 0 : payDate.hashCode());
        result = prime * result + ((receiptMoney == null) ? 0 : receiptMoney.hashCode());
        result = prime * result + ((receiptNo == null) ? 0 : receiptNo.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof LoanTransaction)) {
            return false;
        }
        LoanTransaction other = (LoanTransaction) obj;
        if (balance == null) {
            if (other.balance != null) {
                return false;
            }
        } else if (!balance.equals(other.balance)) {
            return false;
        }
        if (contractNo == null) {
            if (other.contractNo != null) {
                return false;
            }
        } else if (!contractNo.equals(other.contractNo)) {
            return false;
        }
        if (coreName == null) {
            if (other.coreName != null) {
                return false;
            }
        } else if (!coreName.equals(other.coreName)) {
            return false;
        }
        if (coreNo == null) {
            if (other.coreNo != null) {
                return false;
            }
        } else if (!coreNo.equals(other.coreNo)) {
            return false;
        }
        if (custCode == null) {
            if (other.custCode != null) {
                return false;
            }
        } else if (!custCode.equals(other.custCode)) {
            return false;
        }
        if (custName == null) {
            if (other.custName != null) {
                return false;
            }
        } else if (!custName.equals(other.custName)) {
            return false;
        }
        if (factoryName == null) {
            if (other.factoryName != null) {
                return false;
            }
        } else if (!factoryName.equals(other.factoryName)) {
            return false;
        }
        if (factoryNo == null) {
            if (other.factoryNo != null) {
                return false;
            }
        } else if (!factoryNo.equals(other.factoryNo)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (orderNo == null) {
            if (other.orderNo != null) {
                return false;
            }
        } else if (!orderNo.equals(other.orderNo)) {
            return false;
        }
        if (payDate == null) {
            if (other.payDate != null) {
                return false;
            }
        } else if (!payDate.equals(other.payDate)) {
            return false;
        }
        if (receiptMoney == null) {
            if (other.receiptMoney != null) {
                return false;
            }
        } else if (!receiptMoney.equals(other.receiptMoney)) {
            return false;
        }
        if (receiptNo == null) {
            if (other.receiptNo != null) {
                return false;
            }
        } else if (!receiptNo.equals(other.receiptNo)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "LoanTransaction [id=" + id + ", custName=" + custName + ", custCode=" + custCode + ", coreName="
                + coreName + ", coreNo=" + coreNo + ", factoryName=" + factoryName + ", factoryNo=" + factoryNo
                + ", balance=" + balance + ", payDate=" + payDate + ", orderNo=" + orderNo + ", contractNo="
                + contractNo + ", receiptNo=" + receiptNo + ", receiptMoney=" + receiptMoney + "]";
    }

    public void convertTransaction(TransactionDTO dto) {

        this.setBalance(dto.getTradeMoney());

        this.setContractNo(dto.getContractNo());
        this.setCoreName(dto.getEnterpriseName());
        try {
            this.setCoreNo(Long.parseLong(dto.getEnterId()));

            this.setFactoryNo(Long.parseLong(dto.getFundId()));
        }
        catch (Exception e) {
            BTAssert.notNull(null, "交易数据编号转换异常" + dto);
        }
        this.setCustCode(dto.getSupplierCode());
        this.setCustName(dto.getSupplierName());
        this.setFactoryName(dto.getFundName());
        this.setId(dto.getId());
        this.setOrderNo(dto.getOrderNo());
        this.setPayDate(dto.getPayDate());
        this.setReceiptMoney(dto.getReceiptMoney());
        this.setReceiptNo(dto.getReceiptNo());

    }

}
